package com.study.a08threadsafe;

public class MyThread extends Thread {

    static int ticket = 0;

    static Object obj = new Object();

    @Override
    public void run() {

        while (true) {
            synchronized (obj) {
                try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

                if (ticket < 100) {

                    ticket++;
                    System.out.println(getName() + "正在卖第" + ticket + "号票");

                } else {
                    break;
                }
            }
        }
    }
}
